package lab02.test23;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

/**
 * Created by Administrator on 2017/10/31.
 */
public class Birthday {
    public static void main(String[] args) {
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你生日的年份");
    int year = scanner.nextInt();
        System.out.println("请输入你生日的月份");
    int month = scanner.nextInt();
        System.out.println("请输入你生日的天数");
    int day = scanner.nextInt();
        System.out.println("你输入的生日为：" + year + "年" + month + "月" + day + "日");
    Date nowtime = new Date();
    Date date = new Date(year, month, day);
    Calendar nowtime2 = Calendar.getInstance();
        nowtime2.setTime(nowtime);
    Calendar birthdaytime = Calendar.getInstance();
        birthdaytime.setTime(date);
        birthdaytime.add(Calendar.YEAR,-1900);
        birthdaytime.add(Calendar.MONTH,-1);
    int nowday = nowtime2.get(Calendar.DAY_OF_YEAR);
    int nowmonth = nowtime2.get(Calendar.MONTH);

    int birthday = birthdaytime.get(Calendar.DAY_OF_YEAR);
    int birthmonth = birthdaytime.get(Calendar.MONTH);

    Calendar birth = Calendar.getInstance();
    int apartday = 0;

        if (birthmonth > nowmonth) {
        apartday = nowday - birthday;
    } else if (birthmonth < nowmonth) {
        apartday = 365 - (nowday - birthday);
    } else {
        if (birthday > nowday) {
            apartday = birthday - nowday;
        } else if (birthday < nowday) {
            apartday = nowday - birthday;
        } else {
            System.out.println("祝你生日快乐！！");
        }
    }

    int week = birthdaytime.get(Calendar.WEEK_OF_MONTH);

        System.out.println("距离您的生日还有：" + Math.abs(apartday) + "天");
        System.out.println("你的生日是：星期" + week);
}
}


